package btp.SuryaSiddhanta.Planets;

import btp.Calendars.HinduMeanSolarCalendar;

public class HinduMeanLunarCalendar {
	
	public static final double SIDEREAL_YEAR = ((double) Constants.CIVIL_DAYS)/Constants.YUGA;//1577917828.0/4320000.0;
	public static final double SIDEREAL_MONTH = SIDEREAL_YEAR/12;
	public static final double LUNAR_MONTH = ((double) Constants.CIVIL_DAYS)/Constants.LUNAR_MONTHS;
	public static final double LUNAR_DAY = LUNAR_MONTH/30;
	
	int year;
	int month;
	int day;
	
	public HinduMeanLunarCalendar(int year, int month, int day){
		this.year = year;
		this.month = month;
		this.day = day;
	}
	
	public final int getYear() {
		return year;
	}


	public final void setYear(int year) {
		this.year = year;
	}


	public final int getMonth() {
		return month;
	}


	public final void setMonth(int month) {
		this.month = month;
	}


	public final int getDay() {
		return day;
	}


	public final void setDay(int day) {
		this.day = day;
	}

	private static double double_mod(double a, double b)
	{
		return a-Math.floor(a/b);
	}
	
	public static HinduMeanLunarCalendar getHinduLunarFromRD(long rd){
		double sunrise = HinduMeanSolarCalendar.getDayCountFromRD(rd)+0.25;
		double new_moon = Math.floor(sunrise/LUNAR_MONTH)*LUNAR_MONTH;
		boolean leap = SIDEREAL_MONTH-LUNAR_MONTH>=double_mod(new_moon, SIDEREAL_MONTH);
		int month = (int) (Math.ceil(new_moon/SIDEREAL_MONTH)%12 + 1);
		int day = (int) (((int)Math.ceil(sunrise/LUNAR_DAY))%30);
		int year = (int) (Math.ceil((new_moon+SIDEREAL_MONTH)/SIDEREAL_YEAR));
		return new HinduMeanLunarCalendar(year, month, day);
	}
	

}
